package cn.pugle.oj.leetcode;

import cn.pugle.oj.catalog.DynamicProblem;
import cn.pugle.oj.catalog.Unknown;

/**
 * 破test case太多了
 * 0
 * 00
 * 2101
 * <p>
 * 错误写法, 虽然这题testcase多, 但是dp的递推思路确实写错了
 *
 * @author tzp
 * @since 2020/10/23
 */
public class LC91 implements DynamicProblem {
    public int numDecodings(String s) {
        if (s == null || s.length() == 0 || s.equals("0") || s.equals("00")) return 0;
        int total = 1;
        for (int i = 1; i < s.length(); i++) {
            if (s.charAt(i) == '0') {
                continue;
            } else if (isValid(s, i)) {
                total++;
            }
        }
        return total;
    }

    public boolean isValid(String s, int i) {
        char a = s.charAt(i - 1);
        char b = s.charAt(i);
        if (a == '0' || a > '2') {
            return false;
        } else if (a == '2' && b > '6') {
            return false;
        } else if (i < s.length() - 1 && s.charAt(i + 1) == '0') {
            return false;
        } else {
            return true;
        }
    }

    public static void main(String[] args) {
        System.out.println(new LC91().numDecodings("123"));
        System.out.println(new LC91().numDecodings("2101"));
        System.out.println(new LC91().numDecodings("1123"));
        //???5种
        //1 1 2 3
        //11 2 3
        //1 12 3
        //1 1 23
        //11 23
    }
}
